home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / iceb3r1.zip / ice.frm < prev    next >
Text File  |  1995-05-03  |  14KB  |  423 lines

  1. VERSION 2.00
  2. Begin Form frmICE 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "ICE - VB Demonstration"
  6.    ClientHeight    =   4410
  7.    ClientLeft      =   1185
  8.    ClientTop       =   1575
  9.    ClientWidth     =   7680
  10.    ClipControls    =   0   'False
  11.    Height          =   4815
  12.    Icon            =   ICE.FRX:0000
  13.    Left            =   1125
  14.    LinkTopic       =   "Form1"
  15.    MaxButton       =   0   'False
  16.    MinButton       =   0   'False
  17.    ScaleHeight     =   4410
  18.    ScaleWidth      =   7680
  19.    Top             =   1230
  20.    Width           =   7800
  21.    Begin CommandButton cmdAbout 
  22.       Caption         =   "About"
  23.       Height          =   315
  24.       Left            =   2925
  25.       TabIndex        =   20
  26.       Top             =   2850
  27.       Width           =   1215
  28.    End
  29.    Begin CommandButton cmdAdd 
  30.       Caption         =   "&Add -->"
  31.       Height          =   315
  32.       Left            =   2925
  33.       TabIndex        =   6
  34.       Top             =   300
  35.       Width           =   1215
  36.    End
  37.    Begin DriveListBox Drive1 
  38.       Height          =   315
  39.       Left            =   75
  40.       TabIndex        =   5
  41.       Top             =   3225
  42.       Width           =   2640
  43.    End
  44.    Begin DirListBox Dir1 
  45.       Height          =   1155
  46.       Left            =   75
  47.       TabIndex        =   3
  48.       Top             =   1800
  49.       Width           =   2640
  50.    End
  51.    Begin FileListBox File1 
  52.       Height          =   1200
  53.       Left            =   75
  54.       MultiSelect     =   2  'Extended
  55.       TabIndex        =   1
  56.       Top             =   300
  57.       Width           =   2640
  58.    End
  59.    Begin ListBox lstContents 
  60.       Height          =   1980
  61.       Left            =   4350
  62.       Sorted          =   -1  'True
  63.       TabIndex        =   12
  64.       Top             =   900
  65.       Width           =   3240
  66.    End
  67.    Begin TextBox txtArchive 
  68.       Height          =   315
  69.       Left            =   4350
  70.       TabIndex        =   9
  71.       Top             =   300
  72.       Width           =   1965
  73.    End
  74.    Begin Frame Frame1 
  75.       BackColor       =   &H00C0C0C0&
  76.       Caption         =   "Options"
  77.       Height          =   1215
  78.       Left            =   4350
  79.       TabIndex        =   13
  80.       Top             =   3075
  81.       Width           =   3240
  82.       Begin CheckBox cckOverwrite 
  83.          BackColor       =   &H00C0C0C0&
  84.          Caption         =   "Over&write existing files"
  85.          Height          =   315
  86.          Left            =   375
  87.          TabIndex        =   15
  88.          Top             =   675
  89.          Width           =   2340
  90.       End
  91.       Begin CheckBox cckMove 
  92.          BackColor       =   &H00C0C0C0&
  93.          Caption         =   "&Move files"
  94.          Height          =   240
  95.          Left            =   375
  96.          TabIndex        =   14
  97.          Top             =   375
  98.          Width           =   1215
  99.       End
  100.    End
  101.    Begin CommandButton cmdBrowse 
  102.       Caption         =   "&Browse"
  103.       Height          =   315
  104.       Left            =   6375
  105.       TabIndex        =   10
  106.       Top             =   300
  107.       Width           =   1215
  108.    End
  109.    Begin CommonDialog CMDialog1 
  110.       DefaultExt      =   "LZH"
  111.       DialogTitle     =   "Open Archive"
  112.       Filter          =   "LHA files (*.LZH)|*.LZH|All files (*.*)|*.*"
  113.       Left            =   75
  114.       Top             =   3825
  115.    End
  116.    Begin TextBox txtHidden 
  117.       Height          =   465
  118.       Left            =   2700
  119.       TabIndex        =   18
  120.       Top             =   3900
  121.       Visible         =   0   'False
  122.       Width           =   1740
  123.    End
  124.    Begin PictureBox picStatus 
  125.       FillColor       =   &H0000FF00&
  126.       ForeColor       =   &H0000FF00&
  127.       Height          =   315
  128.       Left            =   75
  129.       ScaleHeight     =   285
  130.       ScaleWidth      =   4035
  131.       TabIndex        =   17
  132.       Top             =   3675
  133.       Width           =   4065
  134.    End
  135.    Begin CommandButton cmdExtract 
  136.       Caption         =   "<-- &Extract"
  137.       Height          =   315
  138.       Left            =   2925
  139.       TabIndex        =   7
  140.       Top             =   675
  141.       Width           =   1215
  142.    End
  143.    Begin CommandButton cmdClose 
  144.       Caption         =   "&Close"
  145.       Height          =   315
  146.       Left            =   2925
  147.       TabIndex        =   16
  148.       Top             =   3225
  149.       Width           =   1215
  150.    End
  151.    Begin Label lblArchive 
  152.       BackColor       =   &H00C0C0C0&
  153.       Caption         =   "Arc&hive file:"
  154.       Height          =   225
  155.       Left            =   4350
  156.       TabIndex        =   8
  157.       Top             =   75
  158.       Width           =   1215
  159.    End
  160.    Begin Label lblFiles 
  161.       BackColor       =   &H00C0C0C0&
  162.       Caption         =   "&Files:"
  163.       Height          =   225
  164.       Left            =   75
  165.       TabIndex        =   0
  166.       Top             =   75
  167.       Width           =   1215
  168.    End
  169.    Begin Label lblDir 
  170.       BackColor       =   &H00C0C0C0&
  171.       Caption         =   "&Directories:"
  172.       Height          =   225
  173.       Left            =   75
  174.       TabIndex        =   2
  175.       Top             =   1575
  176.       Width           =   1215
  177.    End
  178.    Begin Label lblDrives 
  179.       AutoSize        =   -1  'True
  180.       BackColor       =   &H00C0C0C0&
  181.       Caption         =   "Dri&ves:"
  182.       Height          =   195
  183.       Left            =   75
  184.       TabIndex        =   4
  185.       Top             =   3000
  186.       Width           =   615
  187.    End
  188.    Begin Label lblContents 
  189.       BackColor       =   &H00C0C0C0&
  190.       Caption         =   "C&ontents:"
  191.       Height          =   240
  192.       Left            =   4350
  193.       TabIndex        =   11
  194.       Top             =   675
  195.       Width           =   1215
  196.    End
  197.    Begin Label lblStatus 
  198.       Alignment       =   2  'Center
  199.       BorderStyle     =   1  'Fixed Single
  200.       Caption         =   "Idle"
  201.       FontBold        =   0   'False
  202.       FontItalic      =   0   'False
  203.       FontName        =   "MS Sans Serif"
  204.       FontSize        =   8.25
  205.       FontStrikethru  =   0   'False
  206.       FontUnderline   =   0   'False
  207.       Height          =   240
  208.       Left            =   75
  209.       TabIndex        =   19
  210.       Top             =   4050
  211.       Width           =   4065
  212.    End
  213. End
  214. ' ---------------------------------------------------------
  215. '       Copyright (C) 1995 Stephen Darlington
  216. '
  217. ' You have a royalty-free right to use, modify, reproduce,
  218. ' and distribute the ICE sample application files
  219. ' (and/or any modified version) in any way you find useful,
  220. ' subject to the limitations outlined in the ICE help file,
  221. ' and provided that you agree that Stephen Darlington has no
  222. ' warranty, obligations, or liability for any sample
  223. ' application files.
  224. ' ---------------------------------------------------------
  225.  
  226. Option Explicit
  227. Declare Function BitBlt Lib "GDI" (ByVal hDestDC As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal XSrc As Integer, ByVal YSrc As Integer, ByVal dwRop As Long) As Integer
  228. Declare Sub ShellAbout Lib "shell.dll" (ByVal hWndOwner As Integer, ByVal lpszAppName As String, ByVal lpszMoreInfo As String, ByVal hIcon As Integer)
  229. Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lparam As Any) As Long
  230. Const WM_USER = &H400
  231. Const LB_SETTABSTOPS = WM_USER + 19
  232. Dim ICEaction As String
  233.  
  234. Sub cmdAbout_Click ()
  235.     Dim sMore$
  236.     sMore$ = "This is a Visual Basic example program "
  237.     sMore$ = sMore$ & "to demonstrate the ICE Compression Library"
  238.     Call ShellAbout(Me.hWnd, App.Title, sMore$, Me.Icon)
  239. End Sub
  240.  
  241. Sub cmdAdd_Click ()
  242.     Dim i As Integer
  243.     Dim lFlags As Long
  244.     Dim iAdded As Integer
  245.     Dim rv As Integer
  246.     Dim afile$
  247.     Dim msg$
  248.     '
  249.     ICEaction = "Freezing"
  250.     iAdded = False
  251.     lFlags = 0
  252.     If (cckMove.Value = 1) Then lFlags = lFlags + ICE_MOVEFILES
  253.     If (cckOverwrite.Value = 1) Then lFlags = lFlags + ICE_OVERWRITEALL
  254.     For i = 0 To file1.ListCount - 1
  255.         If file1.Selected(i) Then
  256.             afile$ = file1.Path
  257.             If (Right$(afile$, 1) <> "\") Then afile$ = afile$ & "\"
  258.             afile$ = afile$ & file1.List(i)
  259.             rv = Freeze(afile$, txtArchive.Text, lFlags)
  260.             If (rv < 0) Then
  261.                 msg$ = "Error " & Format$(rv) & " occured. "
  262.                 msg$ = msg$ & "Please refer to the ICE help file."
  263.                 MsgBox msg$, 15, "Error returned from ICE"
  264.             End If
  265.             iAdded = True
  266.         End If
  267.     Next i
  268.     If iAdded Then ShowContents
  269.     lblStatus.Caption = "Idle"
  270.     picStatus.Cls
  271.     DoEvents
  272. End Sub
  273.  
  274. Sub cmdBrowse_Click ()
  275.     Const OFN_CREATEPROMPT = &H2000&    'Specifies that the dialog box should ask if the user wants to create a file that does not currently exist. This flag automatically sets the OFN_PATHMUSTEXIST and OFN_FILEMUSTEXIST flags.
  276.     Const OFN_HIDEREADONLY = &H4&       'Hides the Read Only check box.
  277.     Const OFN_NOCHANGEDIR = &H8&        'Forces the dialog box to set the current directory to what it was when the dialog box was invoked.
  278.     Const OFN_PATHMUSTEXIST = &H800&    'Specifies that the user can enter only valid path names. If this flag is set and the user enters an invalid path name, a warning message is displayed.
  279.     '
  280.     CMDialog1.Flags = OFN_CREATEPROMPT + OFN_HIDEREADONLY + OFN_NOCHANGEDIR + OFN_PATHMUSTEXIST
  281.     CMDialog1.CancelError = True
  282.     On Error GoTo CancelError
  283.     CMDialog1.Action = 1
  284.     On Error GoTo 0
  285.     DoEvents
  286.     txtArchive.Text = CMDialog1.Filename
  287.     Call ShowContents
  288.     Exit Sub
  289. CancelError:
  290.     On Error GoTo 0
  291.     Exit Sub
  292. End Sub
  293.  
  294. Sub cmdClose_Click ()
  295.     End3D
  296.     End
  297. End Sub
  298.  
  299. Sub cmdExtract_Click ()
  300.     Dim i As Integer
  301.     Dim rv As Integer
  302.     Dim lFlags As Long
  303.     Dim sFile$
  304.     Dim msg$
  305.     Dim Current$
  306.     '
  307.     ICEaction = "Thawing"
  308.     Current$ = CurDir$
  309.     ChDir file1.Path
  310.     lFlags = 0
  311.     If (cckMove.Value = 1) Then lFlags = lFlags + ICE_MOVEFILES
  312.     If (cckOverwrite.Value = 1) Then lFlags = lFlags + ICE_OVERWRITEALL
  313.     For i = 0 To lstContents.ListCount - 1
  314.         If lstContents.Selected(i) Then
  315.             sFile$ = GetPiece(Format$(lstContents.List(i)), Chr(9), 1)
  316.             rv = Thaw(sFile$, txtArchive.Text, lFlags)
  317.             If (rv < 0) Then
  318.                 msg$ = "Error " & Format$(rv) & " occured. "
  319.                 msg$ = msg$ & "Please refer to the ICE help file."
  320.                 MsgBox msg$, 15, "Error returned from ICE"
  321.             End If
  322.         End If
  323.     Next i
  324.     lblStatus.Caption = "Idle"
  325.     picStatus.Cls
  326.     file1.Refresh
  327.     ChDir Current$
  328.     DoEvents
  329. End Sub
  330.  
  331. Sub Dir1_Change ()
  332.     file1.Path = Dir1.Path  ' When Dir changes, set File path.
  333. End Sub
  334.  
  335. Sub Drive1_Change ()
  336.     Dir1.Path = Drive1.Drive    ' When Drive changes, set Dir path.
  337. End Sub
  338.  
  339. Sub Form_Load ()
  340.     Static iTabs(2) As Integer ' the location of the tab stops
  341.     Dim sAlphabet$             ' the alphabet
  342.     Dim AvgChar As Single      ' the width of an average character
  343.     Dim iSpacer As Integer     ' the gaps between columns
  344.     Dim lReturn As Long        ' the value returned from SendMessage
  345.     '
  346.     sAlphabet$ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  347.     AvgChar = (Me.TextWidth(sAlphabet) / 52) / screen.TwipsPerPixelX
  348.     iSpacer = AvgChar * 2
  349.     ' set the tab stop for the maximum possible width of a file name
  350.     iTabs(1) = ((Me.TextWidth("MMMMMMMM.MMM") / screen.TwipsPerPixelX + iSpacer) \ AvgChar) * 4
  351.     ' set the next tab stop for the maximum possible width of the compression ratio
  352.     iTabs(2) = iTabs(1) + ((Me.TextWidth("MMMM") / screen.TwipsPerPixelX + iSpacer) \ AvgChar) * 4
  353.     ' set the tab stops for the listbox
  354.     lReturn = SendMessage(lstContents.hWnd, LB_SETTABSTOPS, 1, iTabs(1))
  355.     '
  356.     ' setup the picturebox as a status bar
  357.     picStatus.AutoRedraw = True
  358.     picStatus.DrawMode = 10
  359.     picStatus.FillStyle = 0
  360.     '
  361.     ' Initialise the ICE library
  362.     Call InitialiseICE(Me.hWnd, txtHidden.hWnd, ICE_PASSPERCENT Or ICE_PASSFILENAME)
  363.     
  364.     ' Get instance handle of project
  365.     hInstance = GetInstance(Me)
  366.     ' start the 3D functions
  367.     Start3D
  368.     ' show this form as 3D
  369.     Make3D Me
  370. End Sub
  371.  
  372. Sub Form_Unload (Cancel As Integer)
  373.     ' stop the 3D functions
  374.     End3D
  375. End Sub
  376.  
  377. Sub ShowContents ()
  378.     Dim i As Integer
  379.     Dim iCounter As Integer
  380.     Dim sLZHfile$
  381.     ReDim files(10) As ICEINFO_TYPE
  382.     '
  383.     lstContents.Clear
  384.     sLZHfile$ = txtArchive.Text
  385.     If (Dir$(sLZHfile$) = "") Then Exit Sub
  386.     iCounter = ListArchiveContents("*.*", sLZHfile$, files())
  387.     For i = 1 To iCounter
  388.         lstContents.AddItem files(i).sFilename & Chr(9) & files(i).sRatio
  389.     Next i
  390. End Sub
  391.  
  392. Sub txtArchive_KeyPress (keyAscii As Integer)
  393.     ' only retrieve the contenst of the file if the user presses return
  394.     If (keyAscii = 13) Then Call ShowContents
  395. End Sub
  396.  
  397. Sub txtHidden_Change ()
  398.     '
  399.     ' this is where VB can react to information passed by ICE.
  400.     Dim pct As Integer
  401.     '
  402.     pct = Val(GetPiece(Format$(txtHidden.Text), "#", 2))
  403.     Call UpdateStatus(pct)
  404.     lblStatus = ICEaction & " " & GetPiece(Format$(txtHidden.Text), "#", 1)
  405.     DoEvents
  406. End Sub
  407.  
  408. Sub UpdateStatus (pctValue As Integer)
  409.     Dim pct$
  410.     Dim rv As Integer
  411.     Const SRCCOPY = &HCC0020
  412.  
  413.     pct$ = Format$(pctValue) & "%"
  414.     picStatus.Cls
  415.     picStatus.CurrentX = (picStatus.ScaleWidth - picStatus.TextWidth(pct$)) \ 2
  416.     picStatus.CurrentY = (picStatus.ScaleHeight - picStatus.TextHeight(pct$)) \ 2
  417.     picStatus.Print pct$
  418.     picStatus.Line (0, 0)-(pctValue * picStatus.ScaleWidth / 100, picStatus.ScaleHeight), picStatus.ForeColor, BF
  419.     rv = BitBlt(picStatus.hDC, 0, 0, picStatus.ScaleWidth, picStatus.ScaleHeight, picStatus.hDC, 0, 0, SRCCOPY)
  420.     DoEvents
  421. End Sub
  422.  
  423.